package com.example.compreshensiveshop.handler;

import com.alipay.api.domain.OrderItem;
import com.example.compreshensiveshop.po.ItemPO;
import com.example.compreshensiveshop.service.ItemService;
import com.example.compreshensiveshop.service.OrdersService;
import com.example.compreshensiveshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PaySuccessHandler {
    @Autowired
    private OrdersService orderService;
    @Autowired
    private ProductService productService;
    @Autowired
    private ItemService itemService;
    public void handleSuccess(Long orderId,Integer status){
        orderService.updateOrderStatus(orderId, status);
        List<ItemPO> itemPOs = itemService.queryByOId(orderId);
        for (ItemPO itemPO : itemPOs) {
            productService.releaseStock(itemPO.getSkuId(), itemPO.getQuantity());
        }
    }

}
